var question = new Array(
"H-COOH",
"CH<sub>3</sub>-COOH",
"CH<sub>3</sub>[CH<sub>2</sub>]<sub>15</sub>COOH",
"C<sub>m</sub>H<sub>2m</sub>O<sub>2</sub>(m≥1)",
"CH<sub>2</sub>=CH-COOH",
"CH<sub>3</sub>[CH<sub>2</sub>]<sub>7</sub>CH=CH[CH<sub>2</sub>]<sub>7</sub>COOH",
"CH<sub>3</sub>-C<sub>6</sub>H<sub>4</sub>-COOH",
"C<sub>6</sub>H<sub>5</sub>-COOH",
"HOOC-COOH",
"HOOC-CH<sub>2</sub>-COOH",
"HOOC-CH<sub>3</sub>-COOH"
);

var resultquestion = new Array(
"0 1 2 3",
"4 5",
"6 7",
"8 9",
"10"
);

$(function() {
    var li1 = '';var li2 = '';var li3 = '';var li4 = '';var li5 = '';var li6 = '';var li7 = ''; var li8 = '';
    $.each(question, function(key, val) {
        if (key%8 == 0) {
                li8 += '<li id="'+key+'" class="ui-state-default ui-corner-all">' + val + '</li>';
        } else if (key%7 == 0) {
                li7 += '<li id="'+key+'" class="ui-state-default ui-corner-all">' + val + '</li>';
        } else if (key%6 == 0) {
                li6 += '<li id="'+key+'" class="ui-state-default ui-corner-all">' + val + '</li>';
        } else if (key%5 == 0) {
                li5 += '<li id="'+key+'" class="ui-state-default ui-corner-all">' + val + '</li>';
        } else if (key%4 == 0) {
                li4 += '<li id="'+key+'" class="ui-state-default ui-corner-all">' + val + '</li>';
        } else if (key%3 == 0) {
                li3 += '<li id="'+key+'" class="ui-state-default ui-corner-all">' + val + '</li>';
        } else if (key%2 == 0) {
                li2 += '<li id="'+key+'" class="ui-state-default ui-corner-all">' + val + '</li>';
        } else {
                li1 += '<li id="'+key+'" class="ui-state-default ui-corner-all">' + val + '</li>';
        }
    });
    $('#sortable1').append(li1);$('#sortable1').append(li2);
    $('#sortable1').append(li3);$('#sortable1').append(li4);$('#sortable1').append(li5);
    $('#sortable1').append(li6);$('#sortable1').append(li7);$('#sortable1').append(li8);
    

    $( "ul.droptrue" ).sortable({
        connectWith: "ul.group",
        cursor: "move",
        placeholder: "ui-state-highlight"
    });

    $( "ul.group" ).sortable({
        connectWith: "ul.droptrue, ul.group",
        cursor: "move",
        placeholder: "ui-state-highlight"
    });

    $( ".group, .droptrue" ).disableSelection();

    $('#submit').click(function() {
        var result1 = new Array();
        var result2 = new Array(); 
        var result3 = new Array();
        var result4 = new Array();
        var result5 = new Array();
        result1 = resultquestion[0].split(' ');
        result2 = resultquestion[1].split(' ');
        result3 = resultquestion[2].split(' ');
        result4 = resultquestion[3].split(' ');
        result5 = resultquestion[4].split(' ');
        var result_1 = 0;
        var result_2 = 0;
        var result_3 = 0;
        var result_4 = 0;
        var result_5 = 0;
        var result_tmp = 1;
        $('#group1').children().each(function(){
                var kid = $(this);
                var tmp = (kid.attr('id'));
                if (jQuery.inArray(tmp, result1) < 0) result_1++;
                if (tmp) result_tmp = 0;
        });
        $('#group2').children().each(function(){
                var kid = $(this);
                var tmp = (kid.attr('id'));
                if (jQuery.inArray(tmp, result2) < 0) result_2++;
        });
        $('#group3').children().each(function(){
                var kid = $(this);
                var tmp = (kid.attr('id'));
                if (jQuery.inArray(tmp, result3) < 0) result_3++;
        });
        $('#group4').children().each(function(){
                var kid = $(this);
                var tmp = (kid.attr('id'));
                if (jQuery.inArray(tmp, result4) < 0) result_4++;
        });
        $('#group5').children().each(function(){
                var kid = $(this);
                var tmp = (kid.attr('id'));
                if (jQuery.inArray(tmp, result5) < 0) result_5++;
        });
        //alert(result_1+'-'+result_2+'-'+result_3+'-'+result_4+'-'+result_5);
        if (result_1 == 0
            && result_2 == 0
            && result_3 == 0
            && result_4 == 0 
            && result_5 == 0 
            && result_tmp == 0) {
                $('.dialogNoteS').dialog({
                    modal: true,
                    buttons: {
                            Ok: function() {
                                location.replace('../sort_1/index.html');
                            }
			}
                });
            } else {
                $('.dialogNoteE').dialog({
                    modal: true,
                    buttons: {
                            Ok: function() {                                
                                $( this ).dialog( "close" );
                            }
			}
                });
            }
    });
});